function RegisterShip(vehicle,plyuni)
	if not servertable["ply"][plyuni]["ShipRegisterd"] then
		timer.Create(plyuni .. "Phase1",1,1,Phase1,vehicle,plyuni)
	end
end

function Phase1 (vehicle,plyuni)
	Msg("Freezing")
	local shipents = constraint.GetAllConstrainedEntities(vehicle) 
	for index,ent in pairs(shipents) do
		local physobj= ent:GetPhysicsObject( )
		physobj:EnableMotion(  false )
	end
	timer.Create(plyuni .. "Phase2",1,1,Phase2,vehicle,plyuni,shipents)
end

function Phase2 (vehicle,plyuni,shipents)
	Msg ("Removing welds")
	for index,ent in pairs(shipents) do
		constraint.RemoveAll(ent)
	end
	timer.Create(plyuni .. "Phase3",1,1,Phase3,vehicle,plyuni,shipents)
end

function Phase3 (vehicle,plyuni,shipents)
	Msg("Get Importatn units")
	local core = nil
	local heavylist = {}
	for index,ent in pairs(shipents) do
		if (ent:GetClass() == "Test" or ent:GetClass() == "Test2") then
			core = ent
		end
		local physobj= ent:GetPhysicsObject( )
		if (physobj:GetMass( ) > 10000) then
			table.insert(heavylist,ent)
		end
	end
	if core then
		timer.Create(plyuni .. "Phase4",1,1,Phase4,vehicle,plyuni,shipents,core,heavylist)
	end
end

function Phase4(vehicle,plyuni,shipents,core,heavylist)
	Msg ("Rewelding")
	for index,ent in pairs(shipents) do
		if not (ent == core) then
			constraint.Weld(ent,core,0,0,0,true)
		end
		if not (ent == vehicle) then
			constraint.Weld(ent,vehicle,0,0,0,true)
		end
	end
	for _,heavyent in pairs(heavylist) do
		for _,heavyent2 in pairs(heavylist) do
			if (heavyent != heavyent2) then
				constraint.Weld(heavyent,heavyent2,0,0,0,true)
			end
		end
	end
	timer.Create(plyuni .. "Phase5",1,1,Phase5,vehicle,plyuni,shipents,core)
end

function Phase5(vehicle,plyuni,shipents,core)
	Msg("For the moment the end")
	for index,ent in pairs(shipents) do
		local physobj= ent:GetPhysicsObject( )
		physobj:EnableMotion(  true )
		physobj:Wake( )
	end
end
